package middlewares

import (
	"github.com/gin-gonic/gin"
	"hosptial-record/model"
	"hosptial-record/strings"
	"net/http"
)

// IsAdminAuth
// 管理员权限验证
func IsAdminAuth() gin.HandlerFunc {
	return func(ctx *gin.Context) {
		// 拿取上下文信息
		claims, _ := ctx.Get(strings.Claims)
		userInfo := claims.(*model.CustomClaims)
		// 获取角色
		if userInfo.Role != 99 {
			ctx.JSON(http.StatusForbidden, gin.H{
				"msg": "权限不足",
			})
			ctx.Abort()
			return
		}
		ctx.Next()
	}
}
